#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
# read data

path = r'/home/yuanfeng/pr_homework/report_02_Titanic/data/train.csv'
data_train = pd.read_csv(path)

#data_train.Survived.value_counts().plot.pie(autopct = '%1.2f%%')# 饼状图

#data_train[['Pclass','Survived']].groupby(['Pclass']).mean().plot.bar()

#data_train[['Sex','Survived']].groupby(['Sex']).mean().plot.bar()

#data_train[['Embarked','Survived']].groupby(['Embarked']).mean().plot.bar()

#plt.figure(figsize=(12,5))
##plt.subplot(121)
#data_train['Age'].hist(bins=80)
#plt.xlabel('Age')
#plt.ylabel('Num')

#bins = [0, 12, 18, 60, 100] 
#data_train['Age_group'] = pd.cut(data_train['Age'], bins)
#by_age = data_train.groupby('Age_group')['Survived'].mean() 
#print(by_age)
#by_age.plot.bar()


data_train['relative'] = data_train.SibSp + data_train.Parch  
data_train.relative.value_counts()
re_Survived = data_train[['relative','Survived']].groupby(['relative'])
print(re_Survived.describe())
re_Survived.mean().plot(kind='bar')
